package
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.HTTPStatusEvent;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.geom.Rectangle;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;
	

	public class Ani_compress_loader
	{
		public var path:String;
		
		private var _index:int;
		
		private var _callBack:Function;
		
		public function Ani_compress_loader(callBack:Function)
		{
			_callBack = callBack;
		}
		public function startLoad():void
		{
			var request:URLRequest = new URLRequest(path);
			var loader:URLLoader = new URLLoader();
			loader.addEventListener(Event.COMPLETE, onComplete3);
			loader.addEventListener(IOErrorEvent.IO_ERROR, onLoadError3);
			loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onLoadError33);
			loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onLoadError33);
			loader.data = null;
			loader.dataFormat = URLLoaderDataFormat.BINARY;
			loader.load(request);
		}
		private function onComplete3(e:Event):void
		{
			e.currentTarget.removeEventListener(Event.COMPLETE, onComplete3);
			e.currentTarget.removeEventListener(IOErrorEvent.IO_ERROR, onLoadError3);
			e.currentTarget.removeEventListener(HTTPStatusEvent.HTTP_STATUS, onLoadError33);
			e.currentTarget.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onLoadError33);
			
			var bytes:ByteArray = (e.currentTarget.data);
			
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onBytesLoaded);
			loader.loadBytes(bytes);
		}
		private function onBytesLoaded(e:Event):void 
		{
			var bitmap:Bitmap = e.target.content as Bitmap;
			e.target.loader.contentLoaderInfo.removeEventListener (Event.COMPLETE, onBytesLoaded);
			
			
			var imgByteArray:ByteArray = bitmap.bitmapData.getPixels(new Rectangle(0, 0, bitmap.width, bitmap.height));
			
			_callBack.apply(null, [imgByteArray, index]);
		} 
		
		private function onLoadError3(e:Event):void
		{
			trace("加载是失败3");
		}
		private function onLoadError33(e:Event):void
		{
			trace("加载是失败33");
		}

		public function get index():int
		{
			return _index;
		}

		public function set index(value:int):void
		{
			_index = value;
		}

	}
}